home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / CullGroupSample / Source / Menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  4.8 KB  |  275 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        MENUS             */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Fonts.h>
  11. #include <Menus.h>
  12. #include <ToolUtils.h>
  13. #include <Devices.h>
  14.  
  15. #include <QD3D.h>
  16. #include <QD3DCamera.h>
  17. #include <QD3DDrawContext.h>
  18. #include <QD3DErrors.h>
  19. #include <QD3DGeometry.h>
  20. #include <QD3DGroup.h>
  21. #include <QD3DIO.h>
  22. #include <QD3DTransform.h>
  23.  
  24. #include "myglobals.h"
  25. #include "qd3d_support.h"
  26. #include "mymenus.h"
  27. #include "misc.h"
  28. #include "main.h"
  29. #include "process.h"
  30. #include "objects.h"
  31. #include "mywindows.h"
  32. #include "3dmf.h"
  33.  
  34. extern    QD3DSetupOutputType        gModelViewInfo;
  35. extern    Boolean                gUseCullingGroups,gShowBBoxes;
  36. extern    int                    gCurrentTest;
  37.  
  38. /******************/
  39. /*  PROTOTYPES    */
  40. /******************/
  41.  
  42. static void HandleSpecialMenuChoice(short theItem);
  43.  
  44.  
  45. /****************************/
  46. /*    CONSTANTS             */
  47. /****************************/
  48.  
  49.                                     // MENU BAR ITEMS //
  50. #define    NOT_A_NORMAL_MENU    -1
  51. #define    APPLE_MENU_ID        400
  52. #define    FILE_MENU_ID        401
  53. #define EDIT_MENU_ID        402
  54. #define SPECIAL_MENU_ID        128
  55.  
  56.  
  57.                                     // EDIT MENU ITEMS //
  58.                                     
  59. enum
  60. {
  61.     UNDO_ITEM    =    1,
  62.     CUT_ITEM    =    3,
  63.     COPY_ITEM    =    4,    
  64.     PASTE_ITEM    =    5,
  65.     CLEAR_ITEM    =    6
  66. };
  67.  
  68.                                     // FILE MENU ITEMS //
  69. enum
  70. {
  71.     OPEN_ITEM    = 1,
  72.     SAVE_ITEM    = 2,
  73.     QUIT_ITEM    = 5
  74. };
  75.  
  76.  
  77.                                     // APPLE MENU ITEMS //
  78. enum                                    
  79. {                                    
  80.     ABOUT_ITEM = 1,
  81.     HELP_ITEM = 2
  82. };
  83.  
  84.  
  85.  
  86. /**********************/
  87. /*     VARIABLES      */
  88. /**********************/
  89.  
  90. MenuHandle    gAppleMenu;
  91.  
  92.  
  93. /******************/
  94. /* INIT MENU BAR  */
  95. /******************/
  96.  
  97. void InitMenuBar(void)
  98. {
  99. Handle    myMenuBar;
  100.         
  101.                     /* ALLOCATE MAIN MENU BAR */
  102.     
  103.     if ((myMenuBar    =    GetNewMBar(400)) == NIL_POINTER)
  104.             DoFatalAlert("\pWhered the menu bar go?!");;
  105.     SetMenuBar(myMenuBar);
  106.     
  107.                     /* SET APPLE MENU */
  108.  
  109.     if ((gAppleMenu    =    GetMenuHandle(400)) == NIL_POINTER)
  110.             DoFatalAlert("\pGetMHandle failed!");
  111.     AppendResMenu (gAppleMenu, 'DRVR');                        // APPEND DESK ACCESSORIES
  112.     
  113.     DrawMenuBar();
  114. }
  115.  
  116.  
  117. /***************************/
  118. /* HANDLE MENU BAR CHOICE  */
  119. /***************************/
  120.  
  121. void HandleMenuChoice(long menuChoice)
  122. {
  123. short    theMenu;
  124. short    theItem;
  125.         
  126.     if    (menuChoice != 0)
  127.     {
  128.         theMenu    =    HiWord(menuChoice);
  129.         theItem    =    LoWord(menuChoice);
  130.         switch    (theMenu)
  131.         {
  132.             case    APPLE_MENU_ID:
  133.                     HandleAppleChoice(theItem);
  134.                     break;
  135.                     
  136.             case    FILE_MENU_ID:
  137.                     HandleFileChoice(theItem);
  138.                     break;
  139.                     
  140.             case    EDIT_MENU_ID:
  141.                     HandleEditChoice(theItem);
  142.                     break;
  143.                     
  144.             case    SPECIAL_MENU_ID:
  145.                     HandleSpecialMenuChoice(theItem);
  146.                     break;
  147.                     
  148.         }
  149.         HiliteMenu(0);
  150.     }
  151. }
  152.  
  153.  
  154. /*****************************/
  155. /* HANDLE APPLE MENU CHOICE  */
  156. /*****************************/
  157.  
  158. void HandleAppleChoice(short theItem)
  159. {
  160. Str255    accName;
  161. short        accNumber;
  162.         
  163.     switch    (theItem)
  164.     {
  165.         case    ABOUT_ITEM:
  166.         
  167.                 Alert(402,NIL_POINTER);
  168.                 break;
  169.         case    HELP_ITEM:
  170.                 Alert(128,NIL_POINTER);
  171.                 break;
  172.             
  173.         default:
  174.                 GetMenuItemText(gAppleMenu,theItem,accName);
  175.                 accNumber    =    OpenDeskAcc(accName);
  176.                 break;
  177.     }
  178. }
  179.  
  180. /****************************/
  181. /* HANDLE FILE MENU CHOICE  */
  182. /****************************/
  183.  
  184. void HandleFileChoice(short theItem)
  185. {
  186.     switch(theItem)
  187.     {
  188.         case    OPEN_ITEM:
  189.                 break;                
  190.  
  191.         case    SAVE_ITEM:
  192.                 Save3DMFModel(&gModelViewInfo, nil, DrawObjects);
  193.                 break;                
  194.  
  195.         case    QUIT_ITEM:
  196.                 DeleteAllObjects();
  197.                 QD3D_DisposeWindowSetup(&gModelViewInfo);
  198.                 DisposeWindow(gModelViewInfo.window);
  199.                 CleanQuit();
  200.                 break;                
  201.     }
  202. }
  203.  
  204.  
  205. /****************************/
  206. /* HANDLE SPECIAL MENU CHOICE  */
  207. /****************************/
  208.  
  209. static void HandleSpecialMenuChoice(short theItem)
  210. {
  211. MenuHandle    aMenu;
  212.  
  213.     switch(theItem)
  214.     {            
  215.         case    1:                // DO IT
  216.                 QD3D_CalcFramesPerSecond();
  217.                 while(!Button())
  218.                     DoModelWindowNullEvent();
  219.                 break;
  220.                 
  221.         case    2:                // USE BBOX
  222.                 gUseCullingGroups = !gUseCullingGroups;
  223.                 aMenu = GetMenuHandle(SPECIAL_MENU_ID);
  224.                 if (gUseCullingGroups)
  225.                     SetItemMark(aMenu, theItem, checkMark);
  226.                 else
  227.                     SetItemMark(aMenu, theItem, noMark);
  228.                 BuildCurrentTest();
  229.                 break;
  230.                 
  231.         case    3:                // SHOW BBOX
  232.                 gShowBBoxes = !gShowBBoxes;
  233.                 aMenu = GetMenuHandle(SPECIAL_MENU_ID);
  234.                 if (gShowBBoxes)
  235.                     SetItemMark(aMenu, theItem, checkMark);
  236.                 else
  237.                     SetItemMark(aMenu, theItem, noMark);
  238.                 BuildCurrentTest();
  239.                 break;
  240.                 
  241.         case    5:                // TriMesh test
  242.                 gCurrentTest = TEST_TRIMESH;
  243.                 BuildCurrentTest();
  244.                 break;
  245.  
  246.         case    6:                // Sphere test
  247.                 gCurrentTest = TEST_SPHERE;
  248.                 BuildCurrentTest();
  249.                 break;
  250.  
  251.         case    7:                // Torus test
  252.                 gCurrentTest = TEST_TORUS;
  253.                 BuildCurrentTest();
  254.                 break;
  255.                 
  256.     }
  257. }
  258.  
  259.  
  260. /****************************/
  261. /* HANDLE EDIT MENU CHOICE  */
  262. /****************************/
  263.  
  264. void HandleEditChoice(short theItem)
  265. {
  266.     SystemEdit(theItem-1);
  267.         
  268.     switch(theItem)
  269.     {
  270.     }
  271. }
  272.  
  273.  
  274.  
  275.